	$(function(){
	/*获取滚动条的位置*/
	var ModalHelper = (function(bodyCls) {
  	var scrollTop;
 	 return {
   	 afterOpen: function() {
      	scrollTop = document.scrollingElement.scrollTop;
      	document.body.classList.add(bodyCls);
      	document.body.style.top = -scrollTop + 'px';
   	 },
   	 beforeClose: function() {
      	document.body.classList.remove(bodyCls);
     	 document.scrollingElement.scrollTop = scrollTop;
    	}
 	 };
	})('gfixed');

		//尺寸选择
		$('.input').click(function(){			
			$('.imgn').attr('src',WST.ROOT+'/Apps/WebApp/View/default/images/Rectangle 19.png');
			$(this).siblings().attr('src',WST.ROOT +'/Apps/WebApp/View/default/images/Group 15.png');
			$('#multiple').val($(this).attr('data'));
			$('#paperType').val($(this).attr('datat'));
			$('#paper').val($(this).attr('datap'))
			realMoney();
			})
		//装帧选择
		$('.input1').click(function(){
			var bookpage = Number( $("#bookPage").text() );
			$('.img1').attr('src',WST.ROOT +'/Apps/WebApp/View/default/images/Rectangle 19.png');
			$(this).siblings().attr('src',WST.ROOT +'/Apps/WebApp/View/default/images/Group 15.png');
			$('#aFourMoney').val($(this).attr('data4'))
			$('#aFiveMoney').val($(this).attr('data5'))
			$('#bookbinding').val($(this).attr('datab'))
			//判断是不是选了韩式无缝装
			if($(this).attr('data-num')==3){
				if(bookpage>70){
					wstMsg("页数超过35页(一页双面)，无法制作！请重新制作");
					$('.img1').attr('src',WST.ROOT +'/Apps/WebApp/View/default/images/Rectangle 19.png')
				}else if(bookpage<70){
					wstMsg("页数少于35页(一页双面)，无法制作！请重新制作");
					$('.img1').attr('src',WST.ROOT +'/Apps/WebApp/View/default/images/Rectangle 19.png')
				}else{
					$('#special').val(1);
				}				
			}else{
				$('#special').val(0);
			}
			realMoney();
		})

		$('.u1 div').click(function(){
			$('.li1').val($(this).text());
			$('.city').hide();
			$('.u1').hide();
		})
		//阻止事件冒泡
		function stopPropagation(e) {
			if (e.stopPropagation)
				e.stopPropagation();
			else
				e.cancelBubble = true;
		}

		$('.cityback').bind('click',function(){
			$('.city').hide();
			$('.select_ul').hide();
	//				$('body').removeClass('gfixed');
	//				ModalHelper.beforeClose();
		});
		$('.choose1').bind('click',function(e){
			stopPropagation(e);
		});
		$('.choose2').bind('click',function(e){
			stopPropagation(e);
		});
		$('.choose3').bind('click',function(e){
			stopPropagation(e);
		});

		//装帧切换
		$('.wei').click(function(){
			$(this).addClass('padding_left').siblings().removeClass('padding_left');
			$('.taozhuang_mian1').css('display','block').siblings().css('display','none');
		})
		$('.zhao').click(function(){
			$(this).addClass('padding_left').siblings().removeClass('padding_left');
			$('.taozhuang_mian2').css('display','block').siblings().css('display','none');
		})

		//装帧隐藏
		$('.delete_img').click(function(){
			$('.zhen').css('display','none');
			$('.main').css('display','block');
			$('body').removeClass('gfixed');
			$('body').css('position','initial');
			ModalHelper.beforeClose();

		})
		//装帧显示
		$('.zhen1').click(function(){
			$('.zhen').css('display','block');
			ModalHelper.afterOpen();
		$('body').addClass('gfixed');
		$('.main').css('display','none');
		})

		realMoney();
});
		function computeWeight(){
			var weight=1;
			var page=Number($('#bookPage').text());
			var type=Number($('#paperType').val());
			var goodsNums=Number($('#goodscount').val());
			var qq=0;
			if(type==4){
				if(page*goodsNums>80){
					qq=Math.ceil((page*goodsNums-80)/80);
					weight=1000+1000*qq;
				}else{
					weight=1000;
				}
			}else if(type==5){
				if(page*goodsNums>160){
					qq=Math.ceil((page*goodsNums-160)/160);
					weight=1000+1000*qq;
				}else{
					weight=1000;
				}
			}
			return weight;
		}
		//修改商品购买数量
		function changeBookNum(flag){
			var num = parseInt($("#goodscount").val(),10);
			var num = num?num:1;
			if(flag==1){
				if(num>1)num = num-1;
			}else if(flag==2){
				num = num+1;
			}
			var maxVal = parseInt($("#goodscount").attr('maxVal'),10);
			if(maxVal<=num)num=maxVal;
			$("#goodscount").val(num);


			var weight=computeWeight();
			if($('.cur').length>0){
				var kd=Number($('.cur').attr('data-price'));
				var add=Number($('.cur').attr('data-add'));
				var money=0;

				if(weight>1000){
					money=kd+((weight/1000)-1)*add;
				}else{
					money=kd;
				}
				$('#kd').text(money.toFixed(2))
			}

			realMoney();
		}


		//计算价格
		function countMoney(){
			var page=Number($('#bookPage').text());
			var type=Number($('#paperType').val());
			var multiple=Number($('#multiple').val());
			var aFourMoney=Number($('#aFourMoney').val());
			var aFiveMoney=Number($('#aFiveMoney').val());
			var goodsNums=Number($('#goodscount').val())
			var total=0;
			var bookbinding=0;
			var Volumes=Math.ceil(page/220);
			var pages=Math.ceil(page/2);
			var relation = Number($('#relation').val())

			if(relation==1 || relation==2){
				var realtotalmoney=0;
				if(pages<=30){
					realtotalmoney=(49.9).toFixed(2)
				}else if(pages>110){
					realtotalmoney=(49.9+(pages-30)*1.5*0.9+18*(Volumes-1)).toFixed(2)
				}else{
					realtotalmoney=(49.9+(pages-30)*1.5*0.9).toFixed(2)
				}
				$('#realtotalmoney').val(realtotalmoney)
				total=realtotalmoney;
			}else{
				if(type==4){
					bookbinding=aFourMoney
				}else if(type==5){
					bookbinding=aFiveMoney
				}
				if(Math.floor(page/220)==0){
					bookbinding=bookbinding*Volumes;
				}
				else if(page%220<=5 && Math.floor(page/220)>0){ //220-225
					bookbinding=bookbinding*(Volumes-1);
				}
				else if(page%220>5 && Math.floor(page/220)>0){ //>225
					bookbinding=bookbinding*Volumes;
				}

				//總價=（页数*纸张价格+封面价格）*数量
				if(pages<30){
					pages=30;
				}
				total=((pages*multiple+bookbinding)*goodsNums).toFixed(2)
			}




			$('#totalMoney').text(total)
		}
		//计算重量
//		var weight=1000;



		//物流选择
		$('.input2').click(function(){
			$('.img2').attr('src',WST.ROOT +'/Apps/WebApp/View/default/images/Rectangle 19.png');
			$(this).siblings().attr('src',WST.ROOT +'/Apps/WebApp/View/default/images/Group 15.png');
			$(this).addClass('cur');
			var weight=computeWeight();
			var type=$(this).attr('data-id');
			var kd=Number($(this).attr('data-price'));
			var add=Number($(this).attr('data-add'));
			var money=0;
			$('#wuliuType').val(type);
			if(weight>1000){
				money=kd+((weight/1000)-1)*add;
			}else{
				money=kd;
			}
			$('#kd').text(money.toFixed(2))
			realMoney();
		})
	
		//总价
		function realMoney(){
			var special=$('#special').val();
			if(special==1){
				specialCountMoney();
			}else{
				countMoney();
			}
			var total=Number($('#totalMoney').text());
			var kd=Number($('#kd').text());
			var real=0;
			real=(total+kd).toFixed(2);
//			console.log(real);
			var expire=1525104000*1000;
			var nowdate = Number(new Date().getTime());
			if(nowdate<expire){real=(real*0.8).toFixed(2)};
			console.log(nowdate);
			var relation = Number($('#relation').val())
			if(relation ==1 || relation ==2){
				real=$('#realtotalmoney').val()
			}
			$('#real').text(real)
		}
			//优惠券事件
			$(function(){
				var iscoupon=$('#iscoupon').val();
			  if(iscoupon==""){
			  	$('#pre-div').css('display','block');
			  	$('#preferential').css('display','none');
			  }else{
			  		$('#pre-div').css('display','none');
			  	$('#preferential').css('display','block');
			  }
			})

		
		var  present=$('.input3').click(function(){
				$('.img3').attr('src', WST.ROOT +'/Apps/WebApp/View/default/images/Group 15.png');
				$('.img4').attr('src', WST.ROOT +'/Apps/WebApp/View/default/images/Rectangle 19.png');
		     	$('.pre-span').text('￥-10:00').css('margin-left','1.4rem');
		        $('.input3').val(1);
		     	var real=$('#real').text();
		     	real=(real-10).toFixed(2);
		     	$('#real').text(real)
			})
	
       
      var present1= $('.input4').click(function(){
				$('.img3').attr('src', WST.ROOT +'/Apps/WebApp/View/default/images/Rectangle 19.png');
				$('.img4').attr('src', WST.ROOT +'/Apps/WebApp/View/default/images/Group 15.png');
				$('.pre-span').text('￥ 0:00').css('margin-left','1.75rem');		
//				var present=Present();
				var iscoupon=$('.input3').val()
				if(iscoupon==1){
				var real=$('#real').text();
		     	real=(Number(real)+10).toFixed(2);
		     	$('#real').text(real)
				}
        })

		//照片数特殊算法
		function specialCountMoney(){
			var page=Number($('#bookPage').text());//页数
			var type=Number($('#paperType').val());//纸张类型
			var aFourMoney=Number($('#aFourMoney').val());//a4价格
			var aFiveMoney=Number($('#aFiveMoney').val());//a5价格
			var goodsNums=Number($('#goodscount').val());//数量
//			alert(page)
//			alert(aFourMoney);
//			alert(aFiveMoney);
			var total=0;
			//多与40页则新成一本书或者回去删照片
			if(page>70){
				alert('删照片')
			}
			var Volumes=Math.ceil(page/70);//一本成书数

			var bookbinding=0
			if(type==4){
				bookbinding=aFourMoney
			}else{
				bookbinding=aFiveMoney
			}
			total=bookbinding*Volumes*goodsNums;
		
		
			$('#totalMoney').text(total)
		}
		